<?php
require_once "includes/config.php";
require_once "includes/functions.php";
require_once('AmazonAPI/.config.inc.php');
require_once('AmazonAPI/CBUI/CBUIMultiUsePipeline.php');
session_start();
$sessid=session_id();
$amount=0;
$order_id=$_REQUEST['order_id'];
//arrays
$recipient_token_arr = array();
$recipient_amount_arr = array();
$tempID_arr = array();
$item_arr = array();
$itemname_arr = array();
$qty_arr = array();
$temp_tax_arr = array();
$extra=0;

$user_q = "SELECT * FROM tbl_orders WHERE order_id = ".$order_id." ";
$user_r = mysql_query($user_q);
$user_row = mysql_fetch_array($user_r);
if(is_array($user_row))
{
	$sqlSelItem="SELECT * FROM tbl_users where user_id='".$user_row['order_comm_to_user_id']."' ";
    $rstSelItem=mysql_query($sqlSelItem);
	$user_row1=mysql_fetch_array($rstSelItem);
	$recipient_token_arr[] = $user_row1['comm_tokenID'];
	if((int)$user_row['order_comm']<10)
	{	
		$charge=($user_row['order_comm']*0.05);
		$charge=$charge+0.05;
		$charge=number_format($charge,2);
		$charge=0;
	}
	else
	{
		$charge=($user_row['order_comm']*0.029);
		$charge=$charge+0.30;
		$charge=number_format($charge,2);		
		$charge=0;
	}	
	$recipient_amount_arr[] =number_format($user_row['order_comm']-$charge,2);
	
	$amount= number_format($user_row['order_comm'],2)-$charge;
}

$tempID_arr[] = $rows['tempid'];
$item_arr[] = $rows['itemid'];
$itemname_arr[] = $rows['itemname'];
$qty_arr[] = $rows['qty'];
$temp_tax_arr[] = number_format($rows['sales_tax'],2);

$_SESSION['order_id'] = $order_id;
$_SESSION['recipient_tokens'] = $recipient_token_arr;
$_SESSION['recipient_amounts'] = $recipient_amount_arr;

$pipeline = new Amazon_FPS_CBUIMultiUsePipeline(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);

$pipeline->setMandatoryParameters("swapen".rand(),  
		H_ROOT."process_comm.php", $amount);
		
//$pipeline->setUsageLimit1("Amount", $amount, "2 Months"); 
$pipeline->setRecipientTokenList(false, $recipient_token_arr);
//optional parameters
$pipeline->addParameter("paymentMethod", "CC");

//$pipeline->addParameter("usageLimitPeriod2", "11/19/2010");

$re_URL = $pipeline->getUrl();
header("location:".$re_URL);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Swapen.com - Buy and Sell</title>
<style type="text/css">
<!--
.style1 {font-weight: bold}
.style2 {color:#fefefe; font-size:12px; font-family: "Trebuchet MS"; background-color:#000000;}
.style3 {font-size:14px; color: #4a4a4a; font-family: "Trebuchet MS";}
-->
</style>

</head>

<body>
<div align="center" class="style1"><span class="style2">Please wait, you are being redirected to selected payment gateway</span><span class="style3">.</span></div>

</body>
</html>
